@extends('admin::layouts.master')
@section('title')
    编辑权益
@endsection
@section('tab')
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form" >
                {{csrf_field()}}
                {{hi_form_hidden('type',$type)}}
                <div class="layui-form-item">
                    <label for="username" class="layui-form-label">
                        <span class="x-red">*</span>名称{{$type}}</label>
                    <div class="layui-input-inline" style="width: 300px;">
                        <input type="text" name="title" lay-verify="required" autocomplete="off" class="layui-input" placeholder="请输入名称"></div>
                </div>

                <div class="layui-form-item">
                    <label for="L_alias" class="layui-form-label">
                        <span class="x-red">*</span>图片</label>
                    <div class="layui-input-inline">
                        <img class="layui-upload-img upload_img" src="admin/images/bg.png" height="100" width="150">
                        <input type="hidden" name="img" value="" lay-verify="pic_log" id="img_url">
                    </div>
                </div>
                @if( $type == 3 )
                <div class="layui-form-item">
                    <label for="username" class="layui-form-label">
                        联系方式</label>
                    <div class="layui-input-inline" style="width: 300px;">
                        <input type="text" name="link_url"  autocomplete="off" class="layui-input" placeholder="请输入联系方式">
                    </div>
                </div>
                @endif

                <div class="layui-form-item">
                    <label for="username" class="layui-form-label">
                        排序</label>
                    <div class="layui-input-inline" style="width: 300px;">
                        <input type="number" max="255" name="sort" autocomplete="off" class="layui-input" placeholder="请输入排序号">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <button class="layui-btn" lay-filter="btn_edit" lay-submit="">确认</button>
                </div>
            </form>
        </div>
    </div>

@endsection

@section('tab_js')
    <script>

        layui.use(['form', 'layer', 'jquery'], function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;
            var is_submit = false;
            //监听提交
            form.on('submit(btn_edit)', function (data) {

                if( is_submit ){
                    return false;
                }
                is_submit = false;
                if( !data.field.img){
                    layer.msg("请上传banner图片", {time: 1000, icon: 5}); return false;
                }
                $.ajax({
                    url: js_url('admin-road-rescue-store_banner'),
                    type: 'post',
                    data: data.field,
                    dataType: "json",
                    success: function (result) {
                        if (result.state === 0) {
                            layer.msg("增加成功", {time: 500, icon: 6}, function () {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                        } else {
                            layer.msg(result.msg, {time: 2000, icon: 5});
                        }
                    }
                });
                return false;

            });


        });
    </script>
@endsection